package servlet;

import pojo.CurriCulum;
import service.LogicService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Array;
import java.sql.SQLException;

/**
 * 2022.03.17测试完成 由吴俊莹编写完成
 * 用户更改课程安排
 */
@WebServlet(name = "/UpdateServlet",value = "/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");

        CurriCulum curriCulum=new CurriCulum();
        LogicService logic=new LogicService();
        int x=0;
        try {
            String xx=req.getParameter("q");
            curriCulum.setId(Integer.parseInt(req.getParameter("id")));
            curriCulum.setTeacherId(logic.teacherID(req.getParameter("tid")));
            curriCulum.setDmy(req.getParameter("sj"));
            curriCulum.setClassHours(req.getParameter("kshi"));
            curriCulum.setClassID(req.getParameter("kban"));
            curriCulum.setCourseName(req.getParameter("kname"));
            curriCulum.setMark(Integer.parseInt(req.getParameter("c")));
            int yc=Integer.parseInt(req.getParameter("yc"));
            String yban=req.getParameter("yban");
            String ykm=req.getParameter("km");
            x=logic.Updateu(curriCulum,xx,yc,ykm,yban);

        } catch (SQLException e) {
            e.printStackTrace();
        }

        PrintWriter out=resp.getWriter();
        out.print(x);
    }
}
